package model;

import dao.Reservation_MealDAO;
import dao.ReservationDAO;
import dao.MealDAO;

public class Reservation_Meal {

	private String meal_name;
	private int quantity;
	private int reservation_id;
	
	private Reservation_MealDAO resmealDAO;
	private ReservationDAO resDAO;
	private MealDAO mealDAO;
	
	public Reservation_Meal() {
		resmealDAO = new Reservation_MealDAO();
		mealDAO = new MealDAO();
		resDAO = new ReservationDAO();
	}
	
	public String getMeal_name() {return meal_name;}
	public int getQuantity() {return quantity;}
	public int getReservation_id() {return reservation_id;}
	
	public void setMeal_name(String meal_name) {this.meal_name = meal_name;}
	public void setQuantity(int quantity) {this.quantity = quantity;}
	public void setReservation_id(int reservation_id) {this.reservation_id = reservation_id;}
	
	public String reserveMeal(int res_id, String meal_name, int quantity) {
		Meal m = mealDAO.select(meal_name);
		Reservation r = resDAO.select(res_id);
		
		if ( r == null || r.getActive() == 0) {
			return "Reservacion inexistente";
		}
		
		if ( m == null || m.getActive() == 0) {
			return "Plato inexistente";
		}
		else {
			Reservation_Meal rm = new Reservation_Meal();
			rm.setMeal_name(meal_name);
			rm.setQuantity(quantity);
			rm.setReservation_id(r.getId());
			
			return "success";
		}		
	}
	
	public boolean cancel(int res_id, String meal_name) {
		Reservation_Meal rm = resmealDAO.select(meal_name, res_id);
		if (rm != null) {
			resmealDAO.delete(meal_name, res_id);
			return true;
		}
		return false;
	}
	
}
